<template>
  <div class="dashboard-editor-container" style="padding-bottom: 30px">
    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
      <div id="courseSales" />
    </el-row>

    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
      <div id="courseQuality" />
    </el-row>

  </div>
</template>

<script>
import { getCourseQuality, getCourseSales } from '@/api/echarts'

export default {
  name: 'DashboardEditor',
  data() {
    return {
      userNums: [],
      dailyLife: {},
      courseSales: {},
      courseQuality: {}
    }
  },
  mounted() {
    this.getCourseSales()
    this.getCourseQuality()
  },
  methods: {
    // 获取课程销量前五
    getCourseSales() {
      getCourseSales().then(res => {
        const xAxis = []
        const series = []
        res.data.forEach(item => {
          xAxis.push(item.name)
          series.push(item.counts)
        })
        this.courseSales.xAxis = xAxis
        this.courseSales.series = series
        this.initCourseSales()
      })
    },
    // 教学评价排行榜
    getCourseQuality() {
      getCourseQuality().then(res => {
        const xAxis = []
        const series = []
        res.data.forEach(item => {
          xAxis.push(item.name)
          series.push(item.counts)
        })
        this.courseQuality.xAxis = xAxis
        this.courseQuality.series = series
        this.initCourseQuality()
      })
    },
    initCourseSales() {
      const chartDom = document.getElementById('courseSales')
      const myChart = this.$echarts.init(chartDom, null, {
        height: 350
      })
      window.onresize = function() {
        myChart.resize()
      }
      const option = {
        backgroundColor: '#FFF',
        title: {
          text: '课程销量排行榜',
          top: '15',
          left: 'center'
        },
        xAxis: {
          type: 'category',
          data: this.courseSales.xAxis
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            data: this.courseSales.series,
            type: 'line'
          }
        ],
        color: ['#91cc75']
      }
      myChart.setOption(option)
    },
    initCourseQuality() {
      const chartDom = document.getElementById('courseQuality')
      const myChart = this.$echarts.init(chartDom, null, {
        height: 350
      })
      window.onresize = function() {
        myChart.resize()
      }
      const option = {
        backgroundColor: '#FFF',
        title: {
          text: '课程好评排行榜',
          top: '15',
          left: 'center'
        },
        xAxis: {
          type: 'category',
          data: this.courseQuality.xAxis
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            data: this.courseQuality.series,
            type: 'line'
          }
        ],
        color: ['#fac858']
      }
      myChart.setOption(option)
    }
  }
}
</script>

<style lang="scss" scoped>
  .emptyGif {
    display: block;
    width: 45%;
    margin: 0 auto;
  }

  .dashboard-editor-container {
    background-color: #e3e3e3;
    min-height: 100vh;
    padding: 50px 60px 0;
    .pan-info-roles {
      font-size: 12px;
      font-weight: 700;
      color: #333;
      display: block;
    }
    .info-container {
      position: relative;
      margin-left: 190px;
      height: 150px;
      line-height: 200px;
      .display_name {
        font-size: 48px;
        line-height: 48px;
        color: #212121;
        position: absolute;
        top: 25px;
      }
    }
  }
</style>
